<?php
class Fav{
	public static function fav_in_array($user){
		$user=mysql_escape_string($user);
		$arrayfav = array();
		$sql_query = mysql_query("SELECT fullpath from ".DATABASE_TABLE_FAV." WHERE user = '$user' ")or die('Erreur de connexion '.mysql_error());
		while ( $query = mysql_fetch_array($sql_query)){
			$arrayfav[] = $query['fullpath'];
		}
		return $arrayfav;
	}
	
	public static function remove_favorite_array($box,$user){
		$tablength = count($box);
		$i = 0;
		while ($i!=$tablength)
		{	
			mysql_query("DELETE FROM ".DATABASE_TABLE_FAV." WHERE id = $box[$i] and user like '".$user."'");		
			$i++;
		}
	}
	
	public static function remove_favorite_element($element,$user){
		$element = mysql_escape_string($element);
		mysql_query("DELETE FROM ".DATABASE_TABLE_FAV." WHERE id = $element and user like '".$user."'");		
	}	

	public static function add_favorite($id,$user){
		$sql_query=mysql_query("SELECT fullpath 
									FROM ".DATABASE_TABLE_FILE."
									WHERE id=$id");
		while ($query = mysql_fetch_array($sql_query) ){
			$tempfullpath = mysql_escape_string($query['fullpath']);
		}
		mysql_query("INSERT INTO ".DATABASE_TABLE_FAV."(fullpath,user) VALUES ('$tempfullpath','".mysql_escape_string($user)."') ") or die(mysql_error());		
	}	
}
?>
